package com.ourcraft.informationcollectionsystem.controller.province;

import com.alibaba.fastjson.JSONObject;
import com.ourcraft.informationcollectionsystem.entity.Company;
import com.ourcraft.informationcollectionsystem.entity.DataReportForm;
import com.ourcraft.informationcollectionsystem.service.province.formEdit.FormEditService;
import com.ourcraft.informationcollectionsystem.utils.authority.AuthorityCode;
import com.ourcraft.informationcollectionsystem.utils.authority.AuthorityValidator;
import com.ourcraft.informationcollectionsystem.utils.response.Result;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("province/formEdit/")
@RestController
@CrossOrigin
@AuthorityValidator(code = AuthorityCode.DATA_ALTER)
public class FormEditController {
    @Autowired
    private FormEditService formEditService;

    @PostMapping("editEnterpriseData")
    public Result<Boolean> editEnterpriseData(@RequestBody JSONObject param, HttpServletRequest request){
        var new_data = new DataReportForm(param);
        return formEditService.editEnterpriseData(new_data, null) ?
                Result.success() : Result.fail();
    }

    @PostMapping("autoCompleteOneBlankEntry")
    public Result<Boolean> autoCompleteOneBlankEntry(@RequestBody JSONObject param, HttpServletRequest request){
        return formEditService.autoCompleteOneBlankEntry(param.getInteger("companyId"), param.getInteger("formId")) ?
                Result.success() : Result.fail();
    }

    @PostMapping("autoCompleteAllBlankEntries")
    public Result<Boolean> autoCompleteAllBlankEntries(@RequestBody JSONObject param, HttpServletRequest request){
        return formEditService.autoCompleteAllBlankEntries() ?
                Result.success() : Result.fail();
    }
}
